import 'dart:io';
import 'package:spring_fairy/api/file_upload_api.dart';
import 'package:spring_fairy/api/point_image_api.dart';
import 'package:spring_fairy/model/mood_point_image.dart';
import 'package:spring_fairy/model/mood_track_point.dart';

//启动另一个线程上传文件
Future<List<MoodPointImage>> uploadImages(List<File> images,MoodTrackPoint point) async {
  FileUploadAPI fileUploadAPI = FileUploadAPI();
  PointImageAPI pointImageAPI = PointImageAPI();

  var result = <MoodPointImage>[];

  for(File file in images) {
    String? path = await fileUploadAPI.uploadFile(file.path);
    if(path == null) {
      continue;
    }

    MoodPointImage moodPointImage = MoodPointImage();
    moodPointImage.pointId = point.id;
    moodPointImage.imageUrl = path;
    MoodPointImage? currentMoodPointImage = await pointImageAPI.addMoodPintImage(moodPointImage);

    if(currentMoodPointImage != null) {
      result.add(currentMoodPointImage);
    }
  }
  return result;


}